worked on writeToArray and a couple other functions