Implementing close window behavior