finished coding function synthesize_plan