Latch added to ensure all threads finish before output is given