Refactored loadScript.js