Several fixes and small changes, grouping with self reference now works better and we sort our nodes when we reuse them