use a write channel rather than writing directly