refactor some template stuff