Cleaned up some debug code, added documentation comments.