Made smatrix code thread safe by removing statics

Changed all static variables which were only being used as local variables to be local variables. This avoids threading problems.