Backports to v0.4.x (#517) until aea393caeb01de981aa2fd27f4c1f0eee7003cd7