Avoid "AttributeError: 'NoneType' object has no attribute 'location'"