update database algorithm