fix algorithm work