added refactored code