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

There must be a smart way to factorise this and the close code, but dont know how in this context. A hint ?