Faster inverse permutations. Other minor code cleanup.