Use unsigned int for counter to avoid sign-comparison