Improvements to module loading code