Backport of PR #836 from master to 2.x branch.

Signed-off-by: Michael Genereux <mgenereu@gmail.com>