Restructuring of the code to hopefully be easier to work with.