Merge rearrange branch into master

Rearranged layout of code by a lot.  I believe it's easier to maintain now, and has better functionality.