fixed read/write to binary functions