added swap function