build tags in linear time instead of quadratic

Reduces runtime from 5.003416s to 0.812732s on current version of Rampant Monkey.