improved tabs logic for selecting current tab