Refactoring + addition of functor for weight of neighbors