replaced thread dict with raw TLS function  to save time