Fix 'index-out-of-range' on empty string -- data[0] is not valid if len(data) == 0