better counter logic, thanks ngoke