Documentation and a bit of cleanup.

Added documentation for non-trivial logic in Contexts, Phases and
TreeTransforms.
Removed redundant vars and casts