cleaned up generation code