added a permutation feature. fixed a bunch of signed-unsigned comparisons