Refactored code v2