Properly use instanceof to check type