Match and replace + improvements