I have rearranged my code so it was easier to read.