Fix some bugs caused by the new template