improve model generation code