Migrate to module code.
Migration to module
Convert most of the previous changes to the module for easier maintenance