refactered countExcludingNullValues
created distanceTolerance constant
return early after error