optimize code
add some test case