Refactored contains on BaseElement.