Refactoring for crossvalidation.