Finally got around to bringing in one of mblakele's pull requests. Brought it into the dev branch.