added length header to the matricies