Optimization: only call recursive_ls once