Fix some minor bugs in template generator