Refactor to support direct encoding (without display).