Solution to second task