Major refactoring - should be a lot easier to read now.