fix speed algorithm problem