MAINT: move the main function to the beginning of the module