Backport #376.