fixes #4173 - taken from GH-1184

successfully tested by @fraenki