Uses isinstance() instead of type() check.
Clean up imports.