Refactored node grouping.