fix some bugs. add docs