Merge pull request #523 from gzm0/backports

Backports to v0.4.x (#517) until 0640376e68a3947f0c2b82e877bdce9fa2735169