Restoring some code from master that was erroneously deleted after the
recent merge.