Updated to do much more dynamic looping for tags.