add tests, add API docs, modified some of the codes