fixed small bug in array indexing