fix bugs in hgen