Fixed templates and some code smell audited.