Added creation of validation set.
Refactored some code.