Fixed a bug causing stack overflows in Chrome

The "trick" I have been using to determine which dependencies are for which script file was causing some circular dependencies. Started referencing document.currentScript for better support in newer browsers.