refactoring loader.js