Changing type checking to isinstance and has_key() to 'in'