script refactoring