optimize generate