Fix doctest so it can be copy-pasted
Fix regression which causes infinite loop