Fixes #4360: correct patch that was not accepted

Previous patch for this ticket was not accepted somehow. Redone the patch, and checked that it merged correctly