Improve AST output routines.
more type checking.