added comments, fixed some bugs, and updated documentation