Added len() safeguard as suggested by @mgedmin 
Somewhere someone has a deranged script... :-)