simplified and faster version of 'prime swaps'