Added the option to write objects into separate files and improved the cleaning