fold the nested loops in bbfdetect