renamed topologicalSort to a more common "linearize"