Bug fix in rule replace operation