refuctored code