Refactoring to make ObjectWriter more robust