Window closing fixed

Fixed a bug related to the handling of window closing