Implemented second problem