Algorithm upto step 4 without error checks