modify algorithm