Trying to rectify the segfault when closing the window