added javadoc, fix some funcs, updated the doc