RF added contains_only to reduce repetition, simplify code based on @stefanv suggestions