added swap method for matrices