Backports for release 3.1.3

@lukasgraf "It works on my machine."