code refactory

use 'isinstance' replace 'type'