Refactor code for template screen