changed logic of pattern search and tags