Divided all the steps in smaller functions