Fix setting of costFunction