add templateDir, also fix bugs