the most natural way to do this is to use recursion