Stabilised and cleaned QPersistence code.