protected code from possible crash by checking for object class