Changed to use recursion