improve deflate function