move stop logic to end body