handle NoneType and other unexpected types of objects better in chars() function