reorganization of script loading code