refactored to use isinstance