Fix the topology generation code

Now it is able to be run.