fix bugs in unloading scripts when changing domains