template changes, refactor code