Fix ast model

In order to support the more advanced features, we need to basically redo the AST. It was not really acting like one anyway.

This is practically a complete rewrite.