Fix potential indexing bug