Refactored tabs functionality. Fixes #329.