refactored tab click code to allow for programatic tab change