Use instanceof for performance