adding algorithm