added saving the best parameters so far and restoring them on training exit