Fixes issue #151

We had here _getType and type variables leaking to global scope, thus recursive calls to serialize were overwriting the type variable.