fix algorithm issue