fixed bug when closing the application