Changed the closestneighbour algorithm as it was quite buggy