added swap code