implement swap method