Re-factored and put in separate files