Fix exit from unicode mode

Retrieve set input method at beginning, and reset to that at end. Only do reset conditionally.