Fixing issue #291 (WIP)

integrate this into onWIndowCloseHandler