Fix runtime errors during script loading