update templates and fix some bugs