updated to handle multiple tags correctly