Fix a bug involving a function recursing indefinitely