fixes and cleanup for deserialization, including suggestion by SP Ong