added swap with if method