updating algorithm