refactor and testing