Fix type variables in serialization updated

Here's an updated version. Test-case included.