fixed bug that causes a seg fault when closing window