add support for '*' wild card and make logic more generic