Clean up tab switching code