Refactoring and code simplification