Moved loadScript() to the end of file