almost finished coding main loop in function synthesize_plan