Fixed a bug where files could potentially be deleted before they were returned to the user