Merging in changes from Matt's pull request, reworked to match other
changes