Trying to fix error: "AttributeError: 'NoneType' object has no attribute 'startswith'"