Code refactored to readable format