Refactored code for simplicity