properly initializing pthread keys and adding a destructor