added fn to calculate objective function