Fixed error in distance equation returning incorrect distances