code refactor and framework for RL agent