Major cleanup and refactoring. Add repository wrapper model.