Update encoding heuristics, and add r2r command