Update value in array causing write error