changed the funciton to minimize with normalizing terms