refactor - move logic from template to controller
fix minor formatting issue