Added thread criation from first thread and sorting function.