Refactor topology generation into its own module