adding function for constructing compressed document (still faulty)