fixed recursive reverse function