Add some docs and fix some bugs