Moved closing the tab into a function of its own