Fixed Index Error and Attribute Error