I've started refactoring the code into methods so that its easir to read and update