Cleaned up tag block with better checking if tags exist