Cleaned up some code and added documentation comments.