Reverse: add guard against empty remainder.

This fixes #521, plus regression test.