This code would be greatly simplified if it just returned instead of recursing.