factored out the vector and matrix class to make them easier to reuse and test.