Is there a specific reason for the whole "terminate" things upon various reasons, like not in lobby and stuff? Maybe you could adapt the windowcheck from notares to avoid the whole logout business, thus save on the occurances of what you never want if using such a bot, that it shuts down.