Improvements following Richard King's feedback.