Union find (minor refactoring)