moved logout operation to ensure logout is processed