Add test and refactoring