completed RTL version of rl_encoder