Fixed small bug with nearest neighbour search