Reduced complexity of getOrphanNodes from O(N^2) to O(N) (see previous
commit)