Corrected bug preventing using the correct index