refactoring some more ast code