Code clean up part 1

A few code clean up changes plus more strict state enforcement.  This
should only be considered 1/2 done. More changes are on the way.