Rrefactored code