An updated version with a couple bug fixes.