recursion for selection retention

Use recursion to ensure that selection retention works for nested nodes