Clean up and organize code.  A couple small logic changes.  Still more cleaning to do, and lots of TODOs.