fixed readArray and writeArray