Apply Dominique patch for issue #321