Fixes/Preparation for json deserializer

This is another rip from #260 which fixes a bunch of things. #260 itself needs
to be rebased on this and could then be merged, so please review carefully.
I just re-run the tests without this patch and they still succeed, so it was another patch which fixed my problems. I will remove this patch from the changeset now.