Changed calculation of max distance in domain to use the range
Deleted whitespace