Code obtained from various sources, but not written, although perhaps edited, by me.