more tweaking of the algorithm