Incorporating changes from @bakercp's pull request to master: 84852322ff