Need to debug the function for opening and writing to the array