Some refactoring...loads more to do.