Backports

THX @DeepDiver1975 @karlitschek