added support to write objects to file