fix logout error issue #92

My previous pull request looked ugly, I'm sorry. Here is new pull request with only one commit. Hope is better.