added thread sorting