added read and write functions