Slightly improve exception handling and relogin logic