improve topLogicalSort