Cleanup of the AST, plus added some util functions