refactor and simplification