tab counter logic