initial script refactor