Lines 1069-1076 in the new code are the same as the original body of this function, just indented. The new logic is just the `if` and the `onClosed()`/`isClosed` stuff on 1077-1078.