Extracted out recursion into separate function to avoid compiler warnings.