Major reorganisation and refactoring