Fix for #380, fallback to last open tab when closing tabs

There's just the same block of code repeated for close and remove, not very good.