Implement better tab closing

When tabs are closed then previously used tabs will be selected,
rather than just the first tab.