Use Math.hypot instead of Math.sqrt to calculate distance