Fix some error cases

In some cases, instanceof does not detect the real Class of an object.