minor refactoring for get_neighbor