Copied code from USC repository. (Did not merge to avoid publishing private code.)