reafactored code