Code changes for the first and second parts including plots