fixed wildcard match ("*")
some cleanup, code dedupe