Final refactoring, with Tim