Tidied topologicalSort, about to remove all mutability
Removing mutability part 1