Recurse instead of while, it works for the tests so we keep it.