Add logout handler and improve login.