fix infinite loop in getRoot.