Copied from classmatch().