refactoring sampleLearning function