Refactoring and cleanup of deserializer code