Updated patch for issue #1631 based on feedback