Replaced toString with instanceof