Tried to optimize the neighbour algorithm.