Optimize and correct testing for string property.

Don't test for "isinstance(x, str) or isinstance(x, unicode)" but for "isinstance(x, basestring)".
Correct some places that forgot to test for unicode (so test for basestring).