refactor of tab handlers which should fix bug with switching tabs and getting into an inconsistent state