A somewhat ugly thread-safety hack.