Sped up permute function, Created test cases and testing R script