worked multi threading version