Incorporated pull request from Burt Beckwith that went to master. Handpicked specific changes to go into the 1.6.1 version.