Refactored deserialization code