refactor/simplify wildcard code