Added retry loop and merging routine.