swap refactor