Fixed indexing array bug