fix up scripting. refactor