some algorithm tweaks