Fixed some bugs, added templates