refactoring Matrix to use ClassTag, TypeTag instead of deprecated Manifest