Added threads for problem 2 and fixed potential race condition in problem 1.