Refactored tab activity code