fix algorithm implementation