Refactored code v4