This is basically upstream commit c95a70bfeae25ba11fbe50fe759a6cdb29388e44 but re-done independently by me because I fixed first and then looked in source control.
This is basically upstream commit c95a70bfeae25ba11fbe50fe759a6cdb29388e44 but re-done independently by me because I fixed first and then looked in source control.