corrected UnboundLocalError about 'ordered_opened'