Major model refactoring, together with new functionality.