improving thread safety