Added code for allocating and deleting matrices.