Fixes #526 (cherry picked from commit e150dd4a66)
e150dd4a66
(cherry picked from commit 6d56abcec1)
6d56abcec1