fix algorithm problem