Fixes for bugs in serialization