updated code to make cross-validation