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

Unsure what you mean. In what way factorise it?