Backports for release 3.1.2

@lukasgraf "It works on my machine."