small change not to loop through the final base with the first one as the list of perms does this for me.