a bit of cleanup

I moved a few things around and added some debug statements to help improve readability.  Let me know what you think!  :)