fix crash after encoding implementation refactor