manual merge with zzorn's thread-safety measures