Fixed bug when closing a tab