Merge with Utter's code. Some corrections.