script refactor