Add more test and refactor