rewrite use recursion