Manually merging fix for issue #1585