add better recursion solution