recursion, much compacter code