Fix bug in tab switching