Most of this looks good to me, but I really don't like the QASSERT macro. If you're fine with it I'll split this up into smaller patches and resubmit the unmodified parts under your name and redo those bits I don't like.