backport of #1066 to stabe45

this is the backport of #1066 to stable45

@bartv2 @karlitschek please review and test - THX