refactored code v.1