refactor and reduce