Refactored checkPermission method.