Corrected the replay loop and error catching logic