fix bug in th generation