fixed array indexing issue