added new refactored code