cleaned up matrix and vector code