Fixed some thread-local logic.