Code improvements and template cleanup.