This backports commit 39baf44c19d0759c42853f5e7d72bd1ba0070321 from the main branch (working on an unstable v0.4) to the v0.3 branch.