Implemented k nearest neighbor search + speedup