Fixed indices errors in code