Issue #1 fixed: on 'close' not correctly handled