simplify code
add more test cases
refined docs