Review recurrence code and fix issues

* Turns out there were a couple of unusual cases that we weren't
  handling correctly, including the referenced bug
* Reworked some of the code, and added test cases for these
  unusual cases.

Bug: 4452794

Change-Id: I02734aefd895bccb8fb2bdcecc3539b1cb06adfd
2 files changed