Update to code for max number of modals to close extra ones as necessary