Couldn't you leave the modifications to `stop_after_phase_X` and then move the emission logic to the end of the phases themselves?