More AST refactoring, and a lot of metaprogramming. Oh god why.