factored the matrix class out into its own file

main was creeping up to 100 lines again.