Refactoring the neighbor computation code so it does not contaminate the tree code