refactoring io stuff and therefore much of the training bits. Also trying to be more functional.
more refactorings for functionality and style