Added crossvalidation code and defined functions for cleaning up fields