refactor script execution