groupByNodes() was buggy in several cases