Added code for step 3 and step 4