Resubmission of pull request #1779

Resubmitting pull request #1779 because something went wrong with the original commit.