Alternative patch for issue #340