Added code and test for the second problem