only log out if necessary