Tweaked to put summary at the top. Work in progress.
Moved code around a little.
Clean up and debug added.