algorithm tweaked