refactor automate scripts