added swap and check functions.