re factored code