implementing read() and write()