add unit test and fix code #2