cleaning up html tag matching logic