fixed many errors with matrices and implemented more tests