add swapOpt with it's helper functions