Write documentation.  Several fixes