finished implementing read and write functions