splitting the code for step 3 and 4