Fixed indexing bug