fix a bug that was preventing editing of documents in cases where the
formatting was off, move the 'document' template to its own file and
some refactoring of controllers and routes.