Impoved class for work with matrix