copies data before exiting