rewrite swap node in pairs