Backport #358 fix from master (46eb5ff)