Apparently the loops can bail early in certain conditions. All tests passing.