Added a distance comparison function. Seriously this damn script needs to be optimized massively so.