Fix AttributeError exception