added comment to porting
changed some isValid and type in isinstance