refactor read/write handlers