fixed a bug with compute_S introduced by the last bug fix