added lots of doc blocks. Cleaned up some in-line comments. Replaced use of "with" statement with try...finally blocks in places where python 2.6 incompatibilities could happen.