window closing implemented in cleaner fashion