Initial refactoring, experimental.