Moved swap code that was misplaced. Commented as it has to be tested yet