Fixed some template bugs