refactor functions, accurate next_train and helpers