Refactor ast