Simplify the code for find_next_goal