Lots more refactoring