refactor and simplify