algorithm not working