moved allocation of memory for tls here and below