Fixing IndexErrors