Comments and cleanup

Added a bunch of comments, and cleaned up some misc code.  Mostly
replacing magic numbers with variables to make things more obvious and
easier to change.  Still need to do that for Z ordering, though.