refactor instanceof for clarity