Fix thread storage bug