re-factored code