This is really ugly and doesn't make the code any nicer, only more complex to understand. The other two commits seem fine, i just cherry-pick them.