Algorithm fix