complete read write function