Added Dr. G's provided code.