Refactor MaybeContext into ThreadsafeContext.