Re-factored dynamic javascript file loading code