Refactored block coding, adding support for opimistic encoding.