Cleaned up the code a bit as well as fixing some issues that I introduced with the last revision.

Most changes were small including a mislabeled array index as well as something that was strangely correct yet may have created some small issues, and I am thinking of going back to the original of it.  See what someone else thinks when I can get their opinion.