reorganized matrix and vector implementations