Fixed bug in perm check