Move Exit encoding to the client functions, including dummy processing.
Fix some bugs introduced by the previous commit.