refactor plan generation.