Fix pointer swap bug