added better handling for login/logout flow