modified algorithm