Generalized from 2 to m neighbors