ClosestFeature function added. Performance fixes.