Restored optimizations in deterministic base swap.
Refactored base swap, tests passing.