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.