refactored to support match tags