change inherits to isDescendant and optimise