have algorithm working