need to refactor a bit to make AST transforms cleaner