Refactoring: simplify code