Replaced goto with recursion.