modified to read/write to binary