added check for which stage subgoal was generated in