modified findOptimalParameters