abstracted away common nested array manipulation in Matrix class