Serialization fixes and tests