Format templates and remove unnecessary code