refactoring for separate train and predict methods