used conditional variables, but it halted on some dataset