added code for 2-fold cross validation