Optimized by using Pool.imap_unordered and Pool.map