fixed some problems with opening and closing window