I'm not so crazy about the approach outlined in the thread, they're basically serializing the object, and I don't think that's what we want to do. But I'm anyway reworking this a bit as per the comments on line 197.