Factored the main into more components