add new function and bug fix
add unittests