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
Merge pull request #381 from glowing-bear/fix-esc

Properly iterate over modals in ESC key handler