Merge pull request #531 from gzm0/backports

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