Fix and refactor Win32 TLS support