add fallback to avoid stack overflow in write