scripts refactor