Refactoring swap code.