Re-factored to make is easier to extend