a bit of re-factoring and correcting the recursive method.