add docs and fixed bugs