Merging in cbbe9688d8c7b2b9c23e66dd7b5b732adddc4a34 from peterfisher, closes #641