refeactored code