Fix some bugs for generator templates