Properly iterate over modals in ESC key handler

the old way included attributes like 'length' and would raise an
exception, causing disconnection via double-esc to fail