Implementing count_wildcards function