Re-factor the JS loader