Code copied to learn from books and other sources. I claim no credit for the work.