rework exploreFromRoot algorithm