Finally tidied everything up and took out a bunch of control statments.