Refactor and simplify code.