Bugfixing: sometimes the wrong tab was being chosen