added check for invalid tags