Refactor hasAll and hasAny