Use isinstance() instead of type() for check quantities