Re-factored code for project #0003