Added optimization to solver