Defining the loss function