more error handling and cleanup temp database directory