Moved scope exit to where it actually makes sense.