minimal changes
added optional Swap mode