factor out the module logic

moving it from `main()` into its own ``__call__`` allows it to be (unit) tested