Fix thread-unsafe builds