refactored code for clarity and consistency