Changed distance to less ambiguous length
Cleaned up code