Update encode implementation.