Add some more type safety to type marshaling