Fix bug when checking for permissions