fixed array indexing bug