Fix doctest and prevent infinite recursion