reorganized code and add doc
fix typo