fixed writing to array