Fix bugs in LZ writer