added document modes, updated document logic