replaced str with basestring in instance checks to support unicode strings