Refactored classification/prediction code