Modularized code and added support for n-folds

Modularized the code into separate functions and altered the code for
cross validation to work for n-folds. Also fixed a bug where the last
fold network always won