fix a bug in function 'swap'