Fix ToplogicalSort bug