Some cleanup, and start using templates.