Improve logout handle and fix typo.

Related to #5131.
[Closes #4815]