fixed application of S matrix (should have been element-wise, not matrix, multiplication with reconstruction vector)