More comments and cleanup. Also split up localization and templating.