Made topsort use a recursive helper function since there was an edge case with the HashSet implementation if non-leaves were duplicated in the tree where the topsort didnt descend fully