Apply Dominique patch for issue #322