tab switching refactored