fix off by one error with the initial permutation mappings (was 1-based not 0-based) and add in the final permutation function too