Refactor to use SortRoots function