Make things more or less thread-safe by passing around context rather than using globals