added document write function