Fix bug when switching tabs