smarter CONTAINS and REPLACE