Off-list Ashutosh Bapat has suggested using a flag instead of counting number of dummy rels and then manipulating on it. That will be simple and smoother.
I agree with his suggestion and updated my patch accordingly.
I have applied patch and checked reported issue. Patch applied cleanly and