Working function of the code