Made context setting thread safe