Docstring improvements, added tests for ast

Mostly code cleanups here. Added tests and docstrings for types in
ast.py and routines.py. Minor fixes in other files.