Verified task 2 logic.