Add documentation and fix some bugs

#22