#6, #3: Added documentation strings. Fixed some bugs.