code and template cleanup