The key to writing for Richard (Pryor) was to just push his buttons and then know when to push the buttons on your cassette recorder. You'd get him started, then surreptitiously start recording when he got inspired and started walking around the room and improvising in character. Then you'd get it all transcribed and take credit for it.
So we had psychiatrists and counselors and therapists around the set regularly, especially for those scenes in which Jason would be dealing with a patient to make sure we were doing it all appropriately.