Fix bugs in generator