refactors, saves current tab in the state