Fix for counter value out of range