Refactor program and analysis trees for tidy up