Improve the is_permutation function a bit and move it to the module
Optimize a bit