Fixed Dustin's Distance Function