refactor and add more test case.