Refactor to provide an intermediate representation of the script