fix for problem in nearest neighbor, plotting is doing something wrong