better permute method