removed the use of globals, added a function to work on the whole training, and fixed a typo
fixed the code to compile
deleted a useless line and added a parameter to save to a specific dir