calculating closest points. No extensive testing done