refactoring + QLearning primitive