Fixes #967

(cherry picked from commit 7618faba51d62edf17b33abbbd3144aa056528cd)