Calculate distance on the fly
-Add comments
-Code cleanup