Moved permute out of the main program to prepare for adaptive runs