Updated function for outputting tags