Refactoring and simplification