Fixes #630

Changes the logic for tab selection
Merge pull request #631 from adamrp/issue_630

Fixes #630