Some styling, better implementation.  Still a few ideas to make the code a little easier.

Still requires some comments in the complex regions