fixed logic error in the permission checking