add testcase & refactor