complete RL implementation