Backport #377.