modified algorithm and thread