Added more test and refactoring