Moved some template code around