Same loop in if and else can this be consolidated to one?
Can we check if shutdown is requested before take()