slightly modified function definition for read and write functions