removed some unnecessary calls to getDistance
find closest target faster
simplified getDistance a bit