Fixing instanceof check