Heavily modified the code for ten-fold cross-validation