added the recursive reverse algo