Fixed sorting of Rstate optional.
Stepped version.