Backport fc6df49

See #947
@LukasReschke