Some more refactoring and reorganisation