Change average to use threads in main function