using sorting and multiple threads