fixes in algorithm