Modified S-matrix computation to be robust against Wood's anomalies.