Refactor and simplify