modified using pthread lib