Fix infinite recursion cases in advance_to_* functions. Fixes #168.