Fixing use of wrong indexes