Refactor error count code.