I did a bit of rework on Umar's work.
This unveiled some more severe bugs (my faults). So, I am quite happy that this kind of code review helps everybody :-)
As last time, I assign this MR to @umar.farooq. Have a look over it, and merge if you are happy.