Some refactoring and reorganisation