Module loading fixes

Fixes and enhancements for loading and using/writing modules.