Refactored code, improved indentation, no functional change