Implement "swap" function.