Adding the first part of the solution for the second task