more fixes for algorithm