added doc and some refactor