reading and writing sorted