Fix length encoding and add recent distance encoding