I'm trying to find closest unit to a certain point.
Here's an outline for how it's done. It's made to be simple, read comment on (meaningless? :P) optimizations below.
Once you understand this outline, you should probably optimize it by storing "Distance Between..." as a variable (so you won't have to check multiple times for the same unit). You should also take care of the point-leaks, and the unit group leak.