modules: fix some memory errors that caused modules to fail to load
modules: refactor.