add more test and refactor