edited runScript function