Refactored code v3