Added query_bb function